<template>
	<view>
		<t-color-picker ref="colorPickerVisit" @confirm="confirm"></t-color-picker>

		<u-list>
			<u-list-item>
				<u-cell title="修改昵称" @click="toChangeUsername()">
					<u-icon slot="right-icon" name="arrow-right" />
				</u-cell>
			</u-list-item>
			<u-list-item>
				<u-cell title="修改密码" @click="toChangePassword()">
					<u-icon slot="right-icon" name="arrow-right" />
				</u-cell>
			</u-list-item>
			<u-list-item>
				<u-cell title="修改界面颜色" @click="openColorPicker()">
					<u-icon slot="right-icon" name="arrow-right" />
				</u-cell>
			</u-list-item>
			<u-list-item>
				<u-cell title="登出" @click="doLogout()">
					<u-icon slot="right-icon" name="arrow-right" />
				</u-cell>
			</u-list-item>
		</u-list>
	</view>
</template>

<script>
	import {
		changeUserInfo,
		logout
	} from '@/api/user/index.js'

	export default {
		name: "userInfo",
		data() {
			return {

			}
		},
		onReady() {
			uni.setNavigationBarColor({
				frontColor: '#000000',
				backgroundColor: uni.getStorageSync('backgroundColor')
			})
		},
		methods: {
			toChangeUsername() {
				uni.navigateTo({
					url: '/pages/user/setting/changeUsername'
				})
			},
			toChangePassword() {
				uni.navigateTo({
					url: '/pages/user/setting/changePassword'
				})
			},
			openColorPicker() {
				this.$refs.colorPickerVisit.open()
			},
			confirm(e) {
				changeUserInfo({
					color: e.hex
				}).then((res) => {
					if (res == null) {
						return
					}
					uni.setStorageSync('backgroundColor', e.hex)
					uni.showToast({
						title: '修改成功',
						icon: 'success'
					});
					uni.navigateTo({
						url: '/pages/index/index'
					})
				})
			},
			doLogout() {
				logout().then(res => {
					uni.showToast({
						title: '登出成功',
						icon: 'success'
					})

					uni.navigateTo({
						url: '/pages/index/index',
					})
				})
			}
		}
	}
</script>

<style scoped>

</style>
